<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" name="idcard" id="idcard" required  >
    <button onclick="f()">提交</button>
</div>
<div id="x"></div>
</body>
<script>
    function f() {
        var x = document.getElementById("x")
        var id = document.getElementById("idcard").value;
        var sex = id.substr(16,1);
        var y = id.substr(6,4);
        var m = id.substr(10,2);
        var d = id.substr(12,2);
        var reg = /^[0-9]{17}[0-9X]$/
        var flag = reg.test(id);
        if (!flag){
            alert("身份证号有误")
        }else {
            if (sex%2==0){
                x.innerHTML="性别女，生日为："+y+"-"+m+"-"+d;

            }else {
                x.innerHTML="性别男，生日为："+y+"-"+m+"-"+d;
            }
        }
    }
</script>
</html>